package com.poi.xml;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class MyTagBeanDefinitionParser extends
		AbstractSingleBeanDefinitionParser {

	//解析元素到BeanDefintionBuilder中.
	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String name = element.getAttribute("name");
		String password = element.getAttribute("password");
		//String email = element.getAttribute("email");
		NodeList nodeList = element.getChildNodes();
		System.out.println("nodeList.getLength():" + nodeList.getLength());
		for (int i = 0; i < nodeList.getLength(); i++) {
			
			Node node = nodeList.item(i);
			System.out.println(node.getNodeName() + "," + node.getNodeValue());
			if ("myTag:email".equals(node.getNodeName())) {
				Element email = (Element)node;
				System.out.println("email:" + email.getFirstChild().getNodeValue());
				System.out.println("email.namespaceURI:" + email.getNamespaceURI()); //
				System.out.println("email.localName:" + email.getLocalName());  //
				
				//对象的属性-属性值.
				builder.addPropertyValue("email", email.getFirstChild().getNodeValue());
			}
		}
		
		
		builder.addPropertyValue("name", name);
		builder.addPropertyValue("password", password);
		//builder.addPropertyValue("email", email);
		
	}

	@Override
	protected Class<?> getBeanClass(Element element) {
		
		return MyTag.class;
	
	}

	
	
}
